import os
import shutil
import re

# def copy_index_scss_to_rn_scss(directory, depth=0):
#     if depth > 5:
#         return

#     for entry in os.scandir(directory):
#         if entry.is_dir():
#             copy_index_scss_to_rn_scss(entry.path, depth + 1)
#         elif entry.name == 'index.scss' and not os.path.exists(os.path.join(directory, 'index.rn.scss')):
#             src_path = entry.path
#             dest_path = os.path.join(directory, 'index.rn.scss')
#             shutil.copy(src_path, dest_path)
#             print(f" Copied {src_path} to {dest_path}")

# # 使用方法
# root_directory = 'E:/node-project/test-sard/src/sard'
# copy_index_scss_to_rn_scss(root_directory)


def remove_if_web_block(directory, depth=0):
    if depth > 5:
        return

    for entry in os.scandir(directory):
        if entry.is_dir():
            remove_if_web_block(entry.path, depth + 1)
        elif entry.name == 'index.rn.scss':
            with open(entry.path, 'r', encoding='utf-8') as file:
                content = file.read()
            new_content = re.sub(r'@include\s+if-web\s*\{\s*[^{}]*?\s*\}', '', content, flags=re.MULTILINE)
            if content != new_content:
                with open(entry.path, 'w', encoding='utf-8') as file:
                    file.write(new_content)
                print(f"Removed @include if-web block from {entry.path}")

# 使用方法
root_directory = 'E:/node-project/test-sard/src/sard'
remove_if_web_block(root_directory)